//
//  LostCarAlarmView.m
//  LocomotiveGuards
//
//  Created by apple on 15/12/1.
//  Copyright (c) 2015年 REDOOR. All rights reserved.
//

#import "Location.h"
#import "LostCarAlarmView.h"
#import "Masonry.h"
#import "PopMsg.h"
#import "UIImageView+WebCache.h"
#import "UITextView+Placeholder.h"

#define BICYCLE_INFORMATION_BACKVIEW_COLOR [UIColor colorWithRed:40 / 255.0 green:151 / 255.0 blue:248 / 255.0 alpha:1] //车辆信息背景图片
#define BICYCLE_PICTURE_WIDTH 0.15 * SCREEN_HEIGHT
#define BICYCLE_PICTURE_HEIGHT 0.15 * SCREEN_HEIGHT
#define BICYCLE_INFORMATION_LABEL_HEIGTH 0.04 * SCREEN_HEIGHT

#define BICYCLE_INFORMATION_LABEL_FRONT [UIFont systemFontOfSize:12]
#define BICYCLE_INFORMATION_LABEL_COLOR [UIColor whiteColor]

#define ALARM_MESSAGE_LABEL_HEIGTH 0.03 * SCREEN_HEIGHT  //报警信息标题高度:电话号码、报案时间、案发地点
#define ALARM_MESSAGE_VALUE_HEIGTH 0.045 * SCREEN_HEIGHT //报警信息标题右侧值的高度
#define ALARM_MESSAGE_INTVAL 0.04 * SCREEN_HEIGHT        //报警信息各标题间距

@interface LostCarAlarmView () <UITextFieldDelegate> {
    Location *_location;
    NSString *province; //省
    NSString *street;   //街道
}
@property (nonatomic, strong) UIImageView *pictureImageView;
@property (nonatomic, strong) UILabel *deviceNumLable;                     //设备号
@property (nonatomic, strong) UILabel *bicycleFrameIdLable;                //车架号
@property (nonatomic, strong) UILabel *brandLable;                         //品牌
@property (nonatomic, strong) UILabel *jurisdictionLable;                  //辖区
@property (nonatomic, strong) UILabel *cusNameLable;                       //车主
@property (nonatomic, strong) UILabel *idCardLable;                        //证件号
@property (nonatomic, strong) UITextField *telnumTextField;                //电话号码
@property (nonatomic, strong) UILabel *cityLable;                          //城市
@property (nonatomic, strong) UIButton *getCurrentLocationButton;          //取当前地址
@property (nonatomic, strong) UITextView *addressSupplementaryInformation; //地址补充信息
@property (nonatomic, strong) UITextView *supplementaryInformation;        //补充信息
@property (nonatomic, strong) UIButton *confirmAlarmButton;                //确认报警

@end

@implementation LostCarAlarmView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _location = [[Location alloc] init];
        [self initUI];
    }
    return self;
}

- (void)dealloc {
    self.lostCarAlarmDelegate = nil;
}

/**
 *  初始化视图控件
 */

- (void)initUI {
    CGFloat tmpFloat = 0;
    CGFloat contentSizeHeight = 0;
    self.backgroundColor = [UIColor whiteColor];

    /**
        车辆信息
     */
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5 * SCREEN_HEIGHT)];
    backView.backgroundColor = BICYCLE_INFORMATION_BACKVIEW_COLOR;
    [self addSubview:backView];
    contentSizeHeight += CGRectGetHeight(backView.frame);

    //车辆图片外边框
    UIImageView *picutreOuterCicleView = [[UIImageView alloc] init];
    picutreOuterCicleView.image = [UIImage imageNamed:@"image_top_carbg"];
    picutreOuterCicleView.layer.cornerRadius = (BICYCLE_PICTURE_WIDTH + 6) / 2;
    picutreOuterCicleView.clipsToBounds = YES;
    [backView addSubview:picutreOuterCicleView];
    [picutreOuterCicleView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(BICYCLE_PICTURE_WIDTH + 6);
        make.height.equalTo(BICYCLE_PICTURE_HEIGHT + 6);
        make.centerX.equalTo(backView.centerX);
        make.top.equalTo(backView.top).with.offset(0.03 * SCREEN_HEIGHT);
    }];

    //车辆图片
    self.pictureImageView = [[UIImageView alloc] init];
    //self.pictureImageView.image = [UIImage imageNamed:@"3pic_photo"];
    self.pictureImageView.layer.cornerRadius = BICYCLE_PICTURE_WIDTH / 2;
    self.pictureImageView.clipsToBounds = YES;
    self.pictureImageView.image = [UIImage imageNamed:@"image_top_car"];
    [backView addSubview:self.pictureImageView];
    [self.pictureImageView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(BICYCLE_PICTURE_WIDTH);
        make.height.equalTo(BICYCLE_PICTURE_HEIGHT);
        make.centerX.equalTo(picutreOuterCicleView.centerX);
        make.centerY.equalTo(picutreOuterCicleView.centerY);
    }];

    // 计算标签之间的距离
    tmpFloat = (CGRectGetHeight(backView.frame) - BICYCLE_PICTURE_HEIGHT - 3 * 0.03 * SCREEN_HEIGHT - 6.0 * BICYCLE_INFORMATION_LABEL_HEIGTH) / 5.0;

    //设备号标题
    UILabel *deviceNumTitleLable = [[UILabel alloc] init];
    deviceNumTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    deviceNumTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    deviceNumTitleLable.textAlignment = NSTextAlignmentRight;
    deviceNumTitleLable.text = @"设备号";
    [backView addSubview:deviceNumTitleLable];
    [deviceNumTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.pictureImageView.bottom).with.offset(0.03 * SCREEN_HEIGHT);
    }];

    //设备号
    self.deviceNumLable = [[UILabel alloc] init];
    self.deviceNumLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.deviceNumLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.deviceNumLable.textAlignment = NSTextAlignmentLeft;
    //self.deviceNumLable.text = @"001236";
    [backView addSubview:self.deviceNumLable];
    [self.deviceNumLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(deviceNumTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(deviceNumTitleLable.top);
    }];

    //车架号标题
    UILabel *bicycleFrameIdTitleLable = [[UILabel alloc] init];
    bicycleFrameIdTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    bicycleFrameIdTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    bicycleFrameIdTitleLable.textAlignment = NSTextAlignmentRight;
    bicycleFrameIdTitleLable.text = @"车架号";
    [backView addSubview:bicycleFrameIdTitleLable];
    [bicycleFrameIdTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.deviceNumLable.bottom).with.offset(tmpFloat);
    }];

    //车架号
    self.bicycleFrameIdLable = [[UILabel alloc] init];
    self.bicycleFrameIdLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.bicycleFrameIdLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.bicycleFrameIdLable.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:self.bicycleFrameIdLable];
    [self.bicycleFrameIdLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bicycleFrameIdTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(bicycleFrameIdTitleLable.top);
    }];

    //品牌标题
    UILabel *brandTitleLable = [[UILabel alloc] init];
    brandTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    brandTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    brandTitleLable.textAlignment = NSTextAlignmentRight;
    brandTitleLable.text = @"品牌";
    [backView addSubview:brandTitleLable];
    [brandTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.bicycleFrameIdLable.bottom).with.offset(tmpFloat);
    }];

    //车架号
    self.brandLable = [[UILabel alloc] init];
    self.brandLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.brandLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.brandLable.textAlignment = NSTextAlignmentLeft;
    //self.brandLable.text = @"爱码";
    [backView addSubview:self.brandLable];
    [self.brandLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(brandTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(brandTitleLable.top);
    }];

    //辖区标题
    UILabel *jurisdictionTitleLable = [[UILabel alloc] init];
    jurisdictionTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    jurisdictionTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    jurisdictionTitleLable.textAlignment = NSTextAlignmentRight;
    jurisdictionTitleLable.text = @"辖区";
    [backView addSubview:jurisdictionTitleLable];
    [jurisdictionTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.brandLable.bottom).with.offset(tmpFloat);
    }];

    //辖区
    self.jurisdictionLable = [[UILabel alloc] init];
    self.jurisdictionLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.jurisdictionLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.jurisdictionLable.textAlignment = NSTextAlignmentLeft;
    //self.jurisdictionLable.text = @"南京市公安局";
    [backView addSubview:self.jurisdictionLable];
    [self.jurisdictionLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(brandTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(jurisdictionTitleLable.top);
    }];

    //车主标题
    UILabel *cusNameTitleLable = [[UILabel alloc] init];
    cusNameTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    cusNameTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    cusNameTitleLable.textAlignment = NSTextAlignmentRight;
    cusNameTitleLable.text = @"车主";
    [backView addSubview:cusNameTitleLable];
    [cusNameTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.jurisdictionLable.bottom).with.offset(tmpFloat);
    }];

    //辖区
    self.cusNameLable = [[UILabel alloc] init];
    self.cusNameLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.cusNameLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.cusNameLable.textAlignment = NSTextAlignmentLeft;
    //self.cusNameLable.text = @"代用名";
    [backView addSubview:self.cusNameLable];
    [self.cusNameLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(brandTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(cusNameTitleLable.top);
    }];

    //证件号标题
    UILabel *idCardTitleLable = [[UILabel alloc] init];
    idCardTitleLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    idCardTitleLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    idCardTitleLable.textAlignment = NSTextAlignmentRight;
    idCardTitleLable.text = @"证件号";
    [backView addSubview:idCardTitleLable];
    [idCardTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.left.equalTo(backView.left);
        make.top.equalTo(self.cusNameLable.bottom).with.offset(tmpFloat);
    }];

    //证件号
    self.idCardLable = [[UILabel alloc] init];
    self.idCardLable.font = BICYCLE_INFORMATION_LABEL_FRONT;
    self.idCardLable.textColor = BICYCLE_INFORMATION_LABEL_COLOR;
    self.idCardLable.textAlignment = NSTextAlignmentLeft;
    //self.idCardLable.text = @"1234567890";
    [backView addSubview:self.idCardLable];
    [self.idCardLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(brandTitleLable.right).with.offset(0.06 * SCREEN_WIDTH);
        make.height.equalTo(BICYCLE_INFORMATION_LABEL_HEIGTH);
        make.right.equalTo(backView.right);
        make.top.equalTo(idCardTitleLable.top);
    }];

    /**
        电话号码
     */
    //电话号码标题
    UILabel *telNumTitleLable = [[UILabel alloc] init];
    telNumTitleLable.font = [UIFont boldSystemFontOfSize:14];
    telNumTitleLable.textColor = RGBCOLOR(148, 148, 148);
    telNumTitleLable.text = @"电话号码";
    [self addSubview:telNumTitleLable];
    [telNumTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0.07 * SCREEN_WIDTH);
        make.height.equalTo(ALARM_MESSAGE_LABEL_HEIGTH);
        make.width.equalTo(0.2 * SCREEN_WIDTH);
        make.top.equalTo(backView.bottom).with.offset(0.05 * SCREEN_HEIGHT);
    }];
    contentSizeHeight += 0.05 * SCREEN_HEIGHT + ALARM_MESSAGE_LABEL_HEIGTH;

    //编辑框
    self.telnumTextField = [[UITextField alloc] init];
    self.telnumTextField.delegate = self;
    self.telnumTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.telnumTextField.textColor = RGBCOLOR(148, 148, 148);
    self.telnumTextField.font = [UIFont systemFontOfSize:12];
    self.telnumTextField.background = [UIImage imageNamed:@"3pic_input01"];
    //self.telnumTextField.text = @"15195996874";
    self.telnumTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0.04 * SCREEN_WIDTH, 0.03 * SCREEN_HEIGHT)];
    self.telnumTextField.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:self.telnumTextField];
    [self.telnumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(telNumTitleLable.right);
        make.height.equalTo(ALARM_MESSAGE_VALUE_HEIGTH);
        make.right.equalTo(backView.right).with.offset(-0.07 * SCREEN_WIDTH);
        make.centerY.equalTo(telNumTitleLable.centerY);
    }];

    //编辑框提示语
    UILabel *editTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0.28 * SCREEN_WIDTH, 0.03 * SCREEN_HEIGHT)];
    editTipLabel.text = @"预留号码可修改";
    editTipLabel.font = [UIFont systemFontOfSize:10];
    editTipLabel.textColor = RGBCOLOR(148, 148, 148);
    editTipLabel.textAlignment = NSTextAlignmentCenter;
    self.telnumTextField.rightView = editTipLabel;
    self.telnumTextField.rightViewMode = UITextFieldViewModeUnlessEditing;
    self.telnumTextField.keyboardType = UIKeyboardTypeNumberPad;

    /**
        报案时间
     */
    UILabel *dateTitleLable = [[UILabel alloc] init];
    dateTitleLable.font = [UIFont boldSystemFontOfSize:14];
    dateTitleLable.textColor = RGBCOLOR(148, 148, 148);
    dateTitleLable.text = @"报案时间";
    [self addSubview:dateTitleLable];
    [dateTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0.07 * SCREEN_WIDTH);
        make.height.equalTo(ALARM_MESSAGE_LABEL_HEIGTH);
        make.width.equalTo(0.2 * SCREEN_WIDTH);
        make.top.equalTo(telNumTitleLable.bottom).with.offset(ALARM_MESSAGE_INTVAL);
    }];
    contentSizeHeight += ALARM_MESSAGE_LABEL_HEIGTH + ALARM_MESSAGE_INTVAL;

    //日期
    self.dateButton = [[UIButton alloc] init];
    [self.dateButton setBackgroundImage:[UIImage imageNamed:@"3pic_input02"] forState:UIControlStateNormal];
    [self.dateButton setTitleColor:RGBCOLOR(148, 148, 148) forState:UIControlStateNormal];
    self.dateButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.dateButton];
    contentSizeHeight += 0.04 * SCREEN_HEIGHT;
    //[self.dateButton setTitle:@"2015.06.03" forState:UIControlStateNormal];
    [self.dateButton addTarget:self action:@selector(dateButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.dateButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dateTitleLable.right);
        make.height.equalTo(ALARM_MESSAGE_VALUE_HEIGTH);
        make.width.equalTo(0.35 * SCREEN_WIDTH);
        make.centerY.equalTo(dateTitleLable.centerY);
    }];

    //时间
    self.timeButton = [[UIButton alloc] init];
    [self.timeButton setBackgroundImage:[UIImage imageNamed:@"3pic_input03"] forState:UIControlStateNormal];
    [self.timeButton setTitleColor:RGBCOLOR(148, 148, 148) forState:UIControlStateNormal];
    self.timeButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.timeButton];
    //[self.timeButton setTitle:@"15:16" forState:UIControlStateNormal];
    [self.timeButton addTarget:self action:@selector(timeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.timeButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dateButton.right).with.offset(0.03 * SCREEN_WIDTH);
        make.height.equalTo(ALARM_MESSAGE_VALUE_HEIGTH);
        make.right.equalTo(backView.right).with.offset(-0.07 * SCREEN_WIDTH);
        make.centerY.equalTo(self.dateButton.centerY);
    }];

    //默认取当前时间
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    formatter.dateFormat = @"yyyy.MM.dd";
    [self.dateButton setTitle:[formatter stringFromDate:date] forState:UIControlStateNormal];
    formatter.dateFormat = @"HH:mm";
    [self.timeButton setTitle:[formatter stringFromDate:date] forState:UIControlStateNormal];

    UILabel *timeEditTipLabel = [[UILabel alloc] init];
    timeEditTipLabel.font = [UIFont boldSystemFontOfSize:9];
    timeEditTipLabel.textColor = RGBCOLOR(148, 148, 148);
    timeEditTipLabel.text = @"当前时间可修改";
    timeEditTipLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:timeEditTipLabel];
    contentSizeHeight += 0.02 * SCREEN_HEIGHT;
    self.contentSize = CGSizeMake(SCREEN_WIDTH, contentSizeHeight);
    [timeEditTipLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.timeButton.centerX);
        make.height.equalTo(0.02 * SCREEN_HEIGHT);
        make.width.equalTo(self.timeButton.width);
        make.top.equalTo(self.timeButton.bottom);
    }];

    /**
        案发地点
     */
    //标题
    UILabel *AddressTitleLable = [[UILabel alloc] init];
    AddressTitleLable.font = [UIFont boldSystemFontOfSize:14];
    AddressTitleLable.textColor = RGBCOLOR(148, 148, 148);
    AddressTitleLable.text = @"案发地点";
    [self addSubview:AddressTitleLable];
    [AddressTitleLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0.07 * SCREEN_WIDTH);
        make.height.equalTo(ALARM_MESSAGE_LABEL_HEIGTH);
        make.width.equalTo(0.2 * SCREEN_WIDTH);
        make.top.equalTo(dateTitleLable.bottom).with.offset(ALARM_MESSAGE_INTVAL);
    }];
    contentSizeHeight += ALARM_MESSAGE_LABEL_HEIGTH + ALARM_MESSAGE_INTVAL;

    //市
    self.cityLable = [[UILabel alloc] init];
    self.cityLable.font = [UIFont systemFontOfSize:13];
    self.cityLable.textColor = RGBCOLOR(148, 148, 148);
    self.cityLable.textAlignment = NSTextAlignmentCenter;
    //self.cityLable.text = @"南京市";
    [self addSubview:self.cityLable];
    [self.cityLable makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(AddressTitleLable.right);
        make.height.equalTo(AddressTitleLable.height);
        make.width.equalTo(0.15 * SCREEN_WIDTH);
        make.centerY.equalTo(AddressTitleLable.centerY);
    }];

    //区
    self.districtButton = [[UIButton alloc] init];
    [self.districtButton setBackgroundImage:[UIImage imageNamed:@"3pic_input03"] forState:UIControlStateNormal];
    [self.districtButton setTitleColor:RGBCOLOR(148, 148, 148) forState:UIControlStateNormal];
    self.districtButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.districtButton addTarget:self action:@selector(districtButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.districtButton];
    //[self.districtButton setTitle:@"江宁区" forState:UIControlStateNormal];
    [self.districtButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cityLable.right).with.offset(0.01 * SCREEN_WIDTH);
        make.height.equalTo(0.04 * SCREEN_HEIGHT);
        make.width.equalTo(0.3 * SCREEN_WIDTH);
        make.centerY.equalTo(AddressTitleLable.centerY);
    }];

    //取当前地址
    self.getCurrentLocationButton = [[UIButton alloc] init];
    [self.getCurrentLocationButton setBackgroundImage:[UIImage imageNamed:@"3pic_btn01"] forState:UIControlStateNormal];
    [self.getCurrentLocationButton setBackgroundImage:[UIImage imageNamed:@"3pic_btn01_on"] forState:UIControlStateHighlighted];
    [self.getCurrentLocationButton addTarget:self action:@selector(getCurrentLocationButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.getCurrentLocationButton];
    [self.getCurrentLocationButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.districtButton.right).with.offset(0.01 * SCREEN_WIDTH);
        make.height.equalTo(0.04 * SCREEN_HEIGHT);
        make.right.equalTo(backView.right).with.offset(-0.07 * SCREEN_WIDTH);
        make.centerY.equalTo(AddressTitleLable.centerY);
    }];

    /**
     *  地址补充信息
     */
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [self addSubview:view];
    [view makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(AddressTitleLable.left);
        make.top.equalTo(AddressTitleLable.bottom).with.offset(0.02 * SCREEN_HEIGHT);
        make.right.equalTo(self.getCurrentLocationButton.right);
        make.height.equalTo(0.48 * SCREEN_HEIGHT);
    }];
    contentSizeHeight += 0.02 * SCREEN_HEIGHT + 0.5 * SCREEN_HEIGHT;
    self.mContentSize = CGSizeMake(SCREEN_WIDTH, contentSizeHeight);
    self.contentSize = CGSizeMake(SCREEN_WIDTH, contentSizeHeight);

    self.addressSupplementaryInformation = [[UITextView alloc] init];
    self.addressSupplementaryInformation.placeholder = @"补充详细信息";
    //[self.addressSupplementaryInformation setBackgroundColor:RGBCOLOR(246, 246, 246)];
    self.addressSupplementaryInformation.font = [UIFont systemFontOfSize:11];
    self.addressSupplementaryInformation.layer.cornerRadius = 10;
    self.addressSupplementaryInformation.layer.borderColor = [RGBCOLOR(148, 148, 148) CGColor];
    self.addressSupplementaryInformation.layer.borderWidth = 1;
    [view addSubview:self.addressSupplementaryInformation];
    [self.addressSupplementaryInformation makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.top);
        make.left.equalTo(view.left);
        make.right.equalTo(view.right);
        make.height.equalTo(0.1 * SCREEN_HEIGHT);
    }];

    //提示
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:10];
    label.textColor = RGBCOLOR(148, 148, 148);
    label.text = @"其他信息:车辆有无特殊特征？有无可疑人员，线索或其他补充";
    [view addSubview:label];
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.addressSupplementaryInformation.centerX);
        make.height.equalTo(0.01 * SCREEN_HEIGHT);
        make.width.equalTo(SCREEN_WIDTH);
        make.top.equalTo(self.addressSupplementaryInformation.bottom).with.offset(ALARM_MESSAGE_INTVAL);
    }];

    //补充信息背景
    self.supplementaryInformation = [[UITextView alloc] init];
    self.supplementaryInformation.font = [UIFont systemFontOfSize:11];
    self.supplementaryInformation.layer.cornerRadius = 10;
    self.supplementaryInformation.layer.borderColor = [RGBCOLOR(148, 148, 148) CGColor];
    self.supplementaryInformation.layer.borderWidth = 1;
    self.supplementaryInformation.placeholder = @"请输入补充信息";
    [view addSubview:self.supplementaryInformation];
    [self.supplementaryInformation makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.bottom).with.offset(0.02 * SCREEN_HEIGHT);
        make.left.equalTo(self.addressSupplementaryInformation.left);
        make.right.equalTo(self.addressSupplementaryInformation.right);
        make.height.equalTo(0.25 * SCREEN_HEIGHT);
    }];

    self.confirmAlarmButton = [[UIButton alloc] init];
    [self.confirmAlarmButton setImage:[UIImage imageNamed:@"3pic_btn02"] forState:UIControlStateNormal];
    [self.confirmAlarmButton setImage:[UIImage imageNamed:@"3pic_btn02_on"] forState:UIControlStateHighlighted];
    [self.confirmAlarmButton addTarget:self action:@selector(confirmAlarmButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.confirmAlarmButton];
    [self.confirmAlarmButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.supplementaryInformation.centerX);
        make.width.equalTo(0.33 * SCREEN_WIDTH);
        make.top.equalTo(self.supplementaryInformation.bottom).with.offset(0.03 * SCREEN_HEIGHT);
        make.bottom.equalTo(view.bottom).with.offset(0.03 * SCREEN_HEIGHT);
    }];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField.text.length >= 11) {
        {
            if ([string isEqual:@""]) {
                return YES;
            }
            return NO;
        }
    }
    return YES;
}

#pragma mark - button clicked handle

/**
 *  日期按钮处理函数
 *
 *  @param _btn <#_btn description#>
 */
- (void)dateButtonClicked:(UIButton *)_btn {

    if (self.lostCarAlarmDelegate) {
        if ([self.lostCarAlarmDelegate respondsToSelector:@selector(dateButtonClicked:)]) {
            [self.lostCarAlarmDelegate performSelector:@selector(dateButtonClicked:) withObject:self.dateButton];
        }
    }
}

/**
 *  时间按钮处理函数
 *
 *  @param _btn <#_btn description#>
 */
- (void)timeButtonClicked:(UIButton *)_btn {
    if (self.lostCarAlarmDelegate) {
        if ([self.lostCarAlarmDelegate respondsToSelector:@selector(timeButtonClicked:)]) {
            [self.lostCarAlarmDelegate performSelector:@selector(timeButtonClicked:) withObject:self.timeButton];
        }
    }
}

/**
 *  取当前地址
 *
 *  @param _btn <#_btn description#>
 */
- (void)getCurrentLocationButtonClicked:(UIButton *)_btn {
    if (_location.locality) {
        self.cityLable.text = _location.locality;
    }
    if (_location.subLocality) {
        [self.districtButton setTitle:_location.subLocality forState:UIControlStateNormal];
    }
    if (_location.detailAddress) {
        self.addressSupplementaryInformation.text = _location.detailAddress;
    }
}


/**
 *  选择区
 *
 *  @param _btn <#_btn description#>
 */
- (void)districtButtonClicked:(UIButton *)_btn {
    if (self.lostCarAlarmDelegate) {
        if ([self.lostCarAlarmDelegate respondsToSelector:@selector(selectSubLocalityButtonClicked:city:)]) {
            //[self.lostCarAlarmDelegate performSelector:@selector(selectSubLocalityButtonClicked:) withObject:self.timeButton];
            [self.lostCarAlarmDelegate selectSubLocalityButtonClicked:province city:self.cityLable.text];
        }
    }
}

/**
 *  确认报警
 *
 *  @param _confirmButton <#_confirmButton description#>
 */
- (void)confirmAlarmButtonClicked:(UIButton *)_confirmButton {
    NSLog(@"----------确认报警-------------");
    NSLog(@"电话号码:%@", self.telnumTextField.text);
    NSLog(@"报案时间:%@ %@", self.dateButton.currentTitle, self.timeButton.currentTitle);
    NSLog(@"案发地点:%@ %@", self.cityLable.text, self.districtButton.currentTitle);

    //电话号码有效性判断
    if (self.telnumTextField.text.length != 11) {
        [PopMsg showMessage:@"手机号码无效" Lasttime:1.0];
        return;
    }

    //报警时间有效性判断
    NSDate *alarmDate = nil;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy.MM.dd HH:mm";
    alarmDate = [formatter dateFromString:[NSString stringWithFormat:@"%@ %@", self.dateButton.currentTitle, self.timeButton.currentTitle]];
    NSLog(@"报警时间:%@\n当前时间:%@", alarmDate, [NSDate date]);
    if (NSOrderedDescending == [alarmDate compare:[NSDate date]]) {
        [PopMsg showMessage:@"报警时间无效" Lasttime:1.0];
        return;
    }

    if ([self.addressSupplementaryInformation.text isEqualToString:@""]) {
        [PopMsg showMessage:@"请补充详细信息" Lasttime:1.0];
        return;
    }

    NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"phonenumber"];
    NSString *bid = [[NSUserDefaults standardUserDefaults] objectForKey:@"bid"];
    if (!loginId || !bid) {
        //        loginId = @"13188888888";
        //        bid = @"11054";
        NSLog(@"请先登录");
        return;
    }

    NSInteger timeInt = (NSInteger)(alarmDate.timeIntervalSince1970);
    timeInt *= 1000;
    //timeInt += NSTimeIntervalSince1970;//Add by xys 2016-08-05
    NSDictionary *paramaDict = @{ @"loginId" : loginId,
                                  @"bid" : bid,
                                  @"phoneNumber" : self.telnumTextField.text,
                                  @"time" : [NSString stringWithFormat:@"%ld", timeInt],
                                  @"province" : province ? province : @"",
                                  @"city" : self.cityLable.text ? self.cityLable.text : @"",
                                  @"district" : self.districtButton.currentTitle ? self.districtButton.currentTitle : @"",
                                  @"street" : street,
                                  @"detailAdress" : self.addressSupplementaryInformation.text ? self.addressSupplementaryInformation.text : @"",
                                  @"content" : self.supplementaryInformation.text ? self.addressSupplementaryInformation.text : @"",
    };
    NSLog(@"%@", paramaDict);
    if (self.lostCarAlarmDelegate && [self.lostCarAlarmDelegate respondsToSelector:@selector(reportLost:)]) {
        [self.lostCarAlarmDelegate performSelector:@selector(reportLost:) withObject:paramaDict];
    }
}


#pragma mark - setter method -

/**
 *  更新界面车辆信息
 *
 *  @param bicycleInfoDict 车辆信息:
 */
- (void)setBicycleInfoDict:(NSDictionary *)bicycleInfoDict {
    if (!bicycleInfoDict) {
        return;
    }

    //设备号
    self.deviceNumLable.text = bicycleInfoDict[@"simId"];
    //车架号
    self.bicycleFrameIdLable.text = bicycleInfoDict[@"frameId"];
    //品牌
    self.brandLable.text = bicycleInfoDict[@"brand"];
    //图片下载
    NSString *urlString = [NSString
    stringWithFormat:@"https://appif.jszhtech.com:8443/ebappif/upImg/%@",
                     bicycleInfoDict[@"picUrl"]];
    [self.pictureImageView
    sd_setImageWithURL:[NSURL URLWithString:urlString]
      placeholderImage:[UIImage imageNamed:@"image_top_car"]];
}

/**
 *  更新界面用户信息
 *
 *  @param userInfoDict 用户信息
 */
- (void)setUserInfoDict:(NSDictionary *)userInfoDict {
    if (!userInfoDict) {
        return;
    }

    self.cusNameLable.text = userInfoDict[@"cusName"] == [NSNull null] ? @"" : userInfoDict[@"cusName"];
    self.idCardLable.text = userInfoDict[@"idCard"] == [NSNull null] ? @"" : userInfoDict[@"idCard"];
    self.telnumTextField.text = userInfoDict[@"cusMobile"] == [NSNull null] ? @"" : userInfoDict[@"cusMobile"];
    self.cityLable.text = userInfoDict[@"city"] == [NSNull null] ? @"" : userInfoDict[@"city"];
    province = userInfoDict[@"province"] == [NSNull null] ? @"" : userInfoDict[@"province"];
    street = userInfoDict[@"street"] == [NSNull null] ? @"" : userInfoDict[@"street"];
    [self.districtButton setTitle:userInfoDict[@"district"] == [NSNull null] ? @"" : userInfoDict[@"district"] forState:UIControlStateNormal];
    self.jurisdictionLable.text = [NSString stringWithFormat:@"%@%@%@", province, self.cityLable.text, self.districtButton.currentTitle];
    self.addressSupplementaryInformation.text = userInfoDict[@"detailAdress"] == [NSNull null] ? nil : userInfoDict[@"detailAdress"];
}

- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled {
    self.telnumTextField.userInteractionEnabled = userInteractionEnabled;
    self.dateButton.userInteractionEnabled = userInteractionEnabled;
    self.timeButton.userInteractionEnabled = userInteractionEnabled;
    self.districtButton.userInteractionEnabled = userInteractionEnabled;
    self.getCurrentLocationButton.userInteractionEnabled = userInteractionEnabled;
    self.addressSupplementaryInformation.userInteractionEnabled = userInteractionEnabled;
    self.supplementaryInformation.userInteractionEnabled = userInteractionEnabled;
    self.confirmAlarmButton.userInteractionEnabled = userInteractionEnabled;
}
@end
